class Solution {
public:
    class cmp{
    public:
      bool operator()(vector<int>& a,vector<int>& b){
        if(a[0] == b[0]) return a[1] < b[1];
        return a[0] < b[0];
      }
    };
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
      if(intervals.size() <= 1){
        return 0;
      }
      sort(intervals.begin(),intervals.end(),cmp());
      int res = 0;
      for(int i = intervals.size() - 2;i >= 0;i--){
        if(intervals[i][1] > intervals[i+1][0]){
          res++;
          intervals[i] = intervals[i+1];
        }
      }
      return res;
    }
};
